<?php
	// Load settings
	// TODO better handling exceptions
	// TODO exception throwing and catching
	include_once 'settings.php';  
	session_start();
	
	general::parse_url_to_request();
	if(isset($_REQUEST['debug'])){
		$_SESSION['debug_mode'] = $_REQUEST['debug'] && constant('ALLOW_DEBUG');
	}
	general::debug('$_REQUEST', $_REQUEST);
	general::debug('$_SESSION', $_SESSION);
	
	// Default controller, controller class and view path
	$main_controller_class = 'main';
	$main_controller_path = constant('TEMPLATE_DIR').'main/main.php';
	$main_view_path = constant('TEMPLATE_DIR').'main/main.tpl';
	$main_template_params = array('controller' => $main_controller_path, 'view' => $main_view_path);
	
	include_once($main_controller_path);
	
	// make default controller and shows it
	$main = new $main_controller_class;
	$compiled = $main->getContent($main_template_params);
	if (empty($GLOBALS['html'])){
		$GLOBALS['html'] = $compiled;
	}
	
	echo $GLOBALS['html'];
?>